package com.fenghongzhang.day004;

import android.content.Context;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;


/**
 * 1.onAttach() :Fragment与Activity有联系。
 * 2.onCreate():创建Fragment
 * 3.onCreateView():创建Fragment视图，尽量不要做耗时操作
 * 4.onActivityCreated():当Activity中的onCreate方法执行完后调用。
 * 5.onStart():启动。
 * 6.onResume():可见
 * 7.onPause()：不可见
 * 8.onStop():停止。
 * 9. onDestroyView() ：销毁Fragment视图
 * 10.onDestroy():销毁fragment对象
 * 11.onDetach():Fragment和Activity解除关联的时候调用
 */
public class BlankFragment extends Fragment {
    private static final String TAG = "BlankFragment";

    public BlankFragment() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(@NonNull Context context) {
        super.onAttach(context);
        Log.i(TAG, "onAttach: ");
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.i(TAG, "onCreate: ");
    }

    //加载界面的
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        Log.i(TAG, "onCreateView: ");
        View inflate = inflater.inflate(R.layout.fragment_blank, container, false);

        TextView textView = inflate.findViewById(R.id.text1);
        textView.setText("hahahahah");

        Button button = inflate.findViewById(R.id.btn);
        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //上下文.
                Toast.makeText(getActivity(), "呵呵呵", Toast.LENGTH_SHORT).show();
            }
        });

        return inflate;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Log.i(TAG, "onActivityCreated: ");
    }

    @Override
    public void onStart() {
        super.onStart();
        Log.i(TAG, "onStart: ");
    }

    @Override
    public void onResume() {
        super.onResume();
        Log.i(TAG, "onResume: ");
    }

    @Override
    public void onPause() {
        super.onPause();
        Log.i(TAG, "onPause: ");
    }

    @Override
    public void onStop() {
        super.onStop();
        Log.i(TAG, "onStop: ");
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Log.i(TAG, "onDestroyView: ");
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "onDestroy: ");
    }

    @Override
    public void onDetach() {
        super.onDetach();
        Log.i(TAG, "onDetach: ");
    }
}
